<template>
    <!-- 页面级别共用的 -->
    <!-- 考试列表 -->
    <AppPageTopInfo title="我的考试" subTitle="">
        <template v-slot:btn>
            <h6>{{ examsToJoinList.length ? '你需要参加的考试如下' : '暂时没有要参加的考试' }}</h6>
            <div v-for="exam in examsToJoinList" :key="exam.id">
                <button class="btn btn-primary" @click="hJumptoExam(exam.id, 'exam')">{{ exam.title }} 参加</button>
            </div>
        </template>
    </AppPageTopInfo>

    <AppPageContentTable
        :cols="[{ label: '考试名称', prop: 'exam-title' }, { label: '得分', prop: 'result' }, { label: '考试时间', prop: 'exam-startAt' }, { label: 'id', prop: 'id' }, { label: '考试状态', prop: 'status' }]"
        :opApi="scoreApi">
        <template v-slot:op="scope">
            <!-- &nbsp;<button @click="hJumptoExam(scope.row.id, 'redoError')">重做错题</button>&nbsp; -->
            <!-- <button type="primary" @click="hJumptoExam(scope.row.id, 'review')">解析试卷</button>&nbsp; -->
            <button type="primary" @click="hJumptoExam(scope.row.id, 'exam')">重新考试</button>&nbsp;
        </template>

    </AppPageContentTable>

</template>
<script setup>
import examApi from "@/api/examApi.js"
import scoreApi from "@/api/scoreApi.js"
import { onMounted } from "vue";
import { useRouter } from "vue-router"
const router = useRouter()
const hJumptoExam = (id, type) => {
    if (type === 'redoError') {

    } else if (type == 'review') {
        window.open(`/#/exam-detail?id=${id}&mode=review`)

    } else if (type == 'exam') {
        window.open(`/#/exam-detail?id=${id}`)
    }
    // router.push(`/exam-detail?id=${row.id}`)
}
const examsToJoinList = ref([])
const getExamToJoin = async () => {
    const res = await examApi.getListToExam()
    console.log(res)
    examsToJoinList.value = res.list
}
onMounted(() => {
    getExamToJoin()
})
</script>
